/*************************************************
 * File:    		SMJS_Document.h
 * Author:  	HouJiong <hou_jiong@163.com>
 * Brief:   		StoneMoneky project.
 *
 * Copyright (c) HouJiong
 *
 *************************************************/

/*
 * History:
 * =======================================
 * 2009-04-10 HouJiong <hou_jiong@163.com> created
 */
 
#ifndef _SMJS_DOCUMENT_H_
#define _SMJS_DOCUMENT_H_

#include <jsapi.h>
#include "SMtypedef.h"
#include "SMXMLDOM.h"
#include "SMFactory.h"



class Document
{
public: 
	Document(SMXMLDOM *dom ):m_SMXMLDOM(dom){};
	std::string GetElementValue(std::string element,std::string attribute);	
	void SetElementValue(std::string element,std::string attribute,std::string value);  
	
private:    
	SMXMLDOM *m_SMXMLDOM;

};

class JSDocument
{
public:	

	JSDocument() : m_pDocument(NULL)	{};		

	virtual ~JSDocument()	
		{		
			//delete m_pDocument;	
			//m_pDocument = NULL;	
		}

	//static JSBool JSGetProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp);	

	//static JSBool JSSetProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp);

	static JSBool JSConstructor(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);	
	
	static void JSDestructor(JSContext *cx, JSObject *obj);	
	
	static JSObject* JSInit(JSContext *cx, JSObject *obj, JSObject *proto = NULL);   
	
	//static JSBool computeReduction(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);

	static JSBool GetElementValue(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
	static JSBool SetElementValue(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
	
	
	static JSBool Print(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval);
	
	static JSClass Document_class;   
	
	void setDocument(Document *document)
		{		m_pDocument = document; 	} 
	Document* getDocument() 
		{		return m_pDocument; 		}
	
protected:private:	
	Document *m_pDocument;   
	static JSPropertySpec Document_properties[];	
	static JSFunctionSpec Document_methods[];
	
	
};
#endif //_SMJS_DOCUMENT_H_